package harima.agameditor.common.control;

import java.io.File;

public class ProjectUtils {

	public boolean createProjectDirectories(String rootPath) {
		File root = new File(rootPath);
		boolean created = root.mkdir();

		if (created) {
			created = createResourcesDir(root);
		}
		if (created) {
			created = createCodeDir(root);
		}
		if (created) {
			created = createMapsDir(root);
		}

		return created;
	}

	private boolean createMapsDir(File root) {
		File maps = new File(root, "maps");
		return maps.mkdir();
	}

	private boolean createCodeDir(File root) {
		File code = new File(root, "code");
		boolean created = code.mkdir();
		created = new File(code, "map_behaivors").mkdir();
		created = new File(code, "map_objects").mkdir();
		return created;
	}

	private boolean createResourcesDir(File root) {
		File resources = new File(root, "resources");
		boolean created = resources.mkdir();
		created = new File(resources, "sounds").mkdir();
		created = new File(resources, "images").mkdir();
		created = new File(resources, "sprites").mkdir();
		created = new File(resources, "tiles").mkdir();
		return created;
	}

	public boolean deleteDirectory(String rootPath) {
		boolean deleted = false;
		File directory = new File(rootPath);
		for(File file : directory.listFiles())
		{
			if(file.isDirectory())
			{
				deleted = deleteDirectory(file.getAbsolutePath());
			}
			else
			{
				deleted = file.delete();
			}
		}
		
		deleted = directory.delete();
		return deleted;
	}

}
